package demo.practice.leetcode_offer;

import demo.practice.ListNode;

import java.util.Stack;

public class Offer06 {

    public static void main(String[] args) {
       ListNode root= new ListNode(1);
        root.next= new ListNode(3);
        root.next.next= new ListNode(2);
        Offer06 offer06= new Offer06();
        offer06.reversePrint(root);

    }
    public int[] reversePrint(ListNode head) {

        if(head==null)
            return new int[0];
        ListNode current= head;
        Stack<Integer> stack= new Stack<>();
        while (current!=null){
            stack.add(current.val);
            current= current.next;
        }

        int len=stack.size();
        int[]target= new int[len];
        for (int i=0;i<len;i++){
            target[i]=stack.pop();
        }

        return target;
    }
}
